package com.beyond.market.cart.controller;

import com.beyond.market.cart.domain.Cart;
import com.beyond.market.cart.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLException;

@Controller
public class CartController {

    @Autowired
    private CartService cartService;

    @RequestMapping("update")
    public String a(){
        return "/update";
    }

    @RequestMapping("/cartUpdate")
    public String update(Integer id, Model model){
        try {
            Integer update = cartService.update(id);
            if(update == 1){
                model.addAttribute("m","修改成功");
                return "/cart/update";
            }
        }catch (SQLException e){
        }
        return null;
    }


    @RequestMapping("/getByPrimaryKey")
    public String getByPrimaryKey(Integer id, ModelMap mm){
        try{
            Cart c = cartService.getByPrimaryKey(id);
            mm.put("c",c);
            return "/cart/getById";
        }catch (SQLException e){
        }
        return null;
    }



}
